package com.frxuexi.mine.viewmodel

import com.frxuexi.lib_base.ApiResp
import com.frxuexi.lib_base.BaseViewModel
import com.frxuexi.lib_base.RequestType
import com.frxuexi.mine.intent.UserIntent
import com.frxuexi.mine.repository.UserRepo
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class UserViewModel @Inject constructor(private val userRepo: UserRepo):BaseViewModel<UserIntent>() {
    override fun handleIntent(it: UserIntent) {
        when(it){
            is UserIntent.login->
                httpRequest(userRepo.login(it.map) as Flow<ApiResp<Any>>)
            is UserIntent.askLeave->{
                httpRequest(userRepo.askLeave(it.map))
            }
            is UserIntent.getLeaves->{
                httpRequest(userRepo.getLeaves(it.status) as Flow<ApiResp<Any>>)
            }
            is UserIntent.approveLeave->
                httpRequest((userRepo.approveLeave(it.map)))
        }
    }
}